import { defineComponent, ref, computed } from "vue";
import PageTitle from "@/components/PageTitle";
import { IFormRef } from "@/components/Form/types";
import ButtonView from "@/components/ButtonView";
import { useRequest } from "./request";
import BannerUploader from "@/components/BannerUploader";
import { FormGroupPropsData } from "@/components/FormGroup/types";
import FormGroup from "@/components/FormGroup";
import EquipmentDetail from "@/pages/equipmentDetail";
export default defineComponent({
  name: "",
  setup() {
    const formRef = ref<IFormRef>();
    const { detail, confirm, productList } = useRequest();
    const data = computed<FormGroupPropsData[]>(() => [
      {
        title: "基本信息",
        data: [
          {
            label: "能检产品",
            type: "multiple",
            key: "productTypeId",
            rules: [
              {
                required: true,
              },
            ],
            typeData: productList.value,
          },
          {
            label: "营业时间",
            type: "timePicker",
            keys: ["startDate", "endDate"],
            rules: [
              {
                required: true,
              },
            ],
          },
        ],
      },
      {
        data: [
          {
            key: "list",
            label: "检测设备",
            type: "uploadPopup",
            view: EquipmentDetail,
          },
        ],
      },
    ]);
    const render1 = () => {
      return (
        <BannerUploader
          v-model={detail.value.entityLogo}
          class="w-full !h-[178px]"
        />
      );
    };
    const render2 = () => {
      return (
        <div class={"p-[10px]"}>
          <FormGroup
            data={data.value}
            v-model={detail.value}
            ref={formRef}
            class="m-child-top-20"
          />
          <ButtonView
            block
            type="primary"
            onClick={() => {
              formRef.value?.submit(({ result, error, submitState }) => {
                submitState && confirm(detail.value);
              });
            }}
            class="!mt-[20px] !h-[40px]"
          >
            确定
          </ButtonView>
        </div>
      );
    };
    return () => {
      return (
        <PageTitle title="检测主页">
          {render1()}
          {render2()}
        </PageTitle>
      );
    };
  },
});
